<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="utf-8" />
        <title>Part.2.D.2-aargs</title>
        <link rel="stylesheet" href="/theme/css/main.css" />

        <!--[if IE]>
            <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
</head>

<body id="index" class="home">
        <header id="banner" class="body">
                <h1><a href="/">PythonTutorials </a></h1>
                <nav><ul>
                    <li><a href="/category/cpp.html">cpp</a></li>
                    <li class="active"><a href="/category/python.html">python</a></li>
                </ul>
                </nav>
        </header><!-- /#banner -->
<section id="content" class="body">
  <article>
    <header>
      <h1 class="entry-title">
        <a href="/Part.2.D.2-aargs.html" rel="bookmark"
           title="Permalink to Part.2.D.2-aargs">Part.2.D.2-aargs</a></h1>
    </header>

    <div class="entry-content">
<footer class="post-info">
        <span>Mon 06 April 2020</span>
<span>| tags: <a href="/tag/python.html">python</a><a href="/tag/progarmming.html">progarmming</a><a href="/tag/excel.html">Excel</a></span>
</footer><!-- /.post-info -->      <h1>关于参数（下）</h1>
<h2>可以接收一系列值的位置参数</h2>
<p>如果你在定义参数的时候，在一个<em>位置参数</em>（Positional Arguments）前面标注了星号，<code>*</code>，那么，这个位置参数可以接收一系列值，在函数内部可以对这一系列值用 <code>for ... in ...</code> 循环进行逐一的处理。</p>
<p>带一个星号的参数，英文名称是 “Arbitrary Positional Arguments”，姑且翻译为 “随意的位置参数”。</p>
<p>还有带两个星号的参数，一会儿会讲到，英文名称是 “Arbitrary Keyword Arguments”，姑且翻译为 “随意的关键字参数”。</p>
<blockquote>
<p>有些中文书籍把 “Arbitrary Positional Arguments” 翻译成 “可变位置参数”。事实上，在这样的地方，无论怎样的中文翻译都是令人觉得非常吃力的。前面的这个翻译还好了，我还见过把 “Arbitrary Keyword Arguments” 翻译成 “武断的关键字参数” 的 —— 我觉得这样的翻译肯定会使读者产生说不明道不白的疑惑。</p>
<p>所以，<strong>入门之后就尽量只用英文</strong>是个好策略。虽然刚开始有点吃力，但后面会很省心，很长寿 —— 是呀，少浪费时间、少浪费生命，其实就相当于更长寿了呀！</p>
</blockquote>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">say_hi</span><span class="p">(</span><span class="o">*</span><span class="n">names</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
        <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">&#39;Hi, {name}!&#39;</span><span class="p">)</span>
<span class="n">say_hi</span><span class="p">()</span>
<span class="n">say_hi</span><span class="p">(</span><span class="s1">&#39;ann&#39;</span><span class="p">)</span>
<span class="n">say_hi</span><span class="p">(</span><span class="s1">&#39;mike&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">,</span> <span class="s1">&#39;zeo&#39;</span><span class="p">)</span>
</pre></div>


<div class="highlight"><pre><span></span>Hi, ann!
Hi, mike!
Hi, john!
Hi, zeo!
</pre></div>


<p><code>say_hi()</code> 这一行没有任何输出。因为你在调用函数的时候，没有给它传递任何值，于是，在函数内部代码执行的时候，<code>name in names</code> 的值是 <code>False</code>，所以，<code>for</code> 循环内部的代码没有被执行。</p>
<p>在函数内部，是把 <code>names</code> 这个参数当作容器处理的 —— 否则也没办法用 <code>for ... in ...</code> 来处理。而在调用函数的时候，我们是可以将一个容器传递给函数的 Arbitrary Positional Arguments 的 —— 做法是，在调用函数的时候，在参数前面加上星号 <code>*</code>：</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">say_hi</span><span class="p">(</span><span class="o">*</span><span class="n">names</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
        <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">&#39;Hi, {name}!&#39;</span><span class="p">)</span>

<span class="n">names</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;mike&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">,</span> <span class="s1">&#39;zeo&#39;</span><span class="p">)</span>
<span class="n">say_hi</span><span class="p">(</span><span class="o">*</span><span class="n">names</span><span class="p">)</span>
</pre></div>


<div class="highlight"><pre><span></span>Hi, mike!
Hi, john!
Hi, zeo!
</pre></div>


<p>实际上，因为以上的 <code>say_hi(*names)</code> 函数内部就是把接收到的参数当作容器处理的，于是，在调用这个函数的时候，向它传递任何容器都会被同样处理：</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">say_hi</span><span class="p">(</span><span class="o">*</span><span class="n">names</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
        <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">&#39;Hi, {name}!&#39;</span><span class="p">)</span>

<span class="n">a_string</span> <span class="o">=</span> <span class="s1">&#39;Python&#39;</span>
<span class="n">say_hi</span><span class="p">(</span><span class="o">*</span><span class="n">a_string</span><span class="p">)</span>

<span class="n">a_range</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="n">say_hi</span><span class="p">(</span><span class="o">*</span><span class="n">a_range</span><span class="p">)</span>

<span class="n">a_list</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">))</span>
<span class="n">say_hi</span><span class="p">(</span><span class="o">*</span><span class="n">a_list</span><span class="p">)</span>

<span class="n">a_dictionary</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;ann&#39;</span><span class="p">:</span><span class="mi">2321</span><span class="p">,</span> <span class="s1">&#39;mike&#39;</span><span class="p">:</span><span class="mi">8712</span><span class="p">,</span> <span class="s1">&#39;joe&#39;</span><span class="p">:</span> <span class="mi">7610</span><span class="p">}</span>
<span class="n">say_hi</span><span class="p">(</span><span class="o">*</span><span class="n">a_dictionary</span><span class="p">)</span>
</pre></div>


<div class="highlight"><pre><span></span>Hi, P!
Hi, y!
Hi, t!
Hi, h!
Hi, o!
Hi, n!
Hi, 0!
Hi, 1!
Hi, 2!
Hi, 3!
Hi, 4!
Hi, 5!
Hi, 6!
Hi, 7!
Hi, 8!
Hi, 9!
Hi, 10!
Hi, 9!
Hi, 8!
Hi, 7!
Hi, 6!
Hi, 5!
Hi, 4!
Hi, 3!
Hi, 2!
Hi, 1!
Hi, ann!
Hi, mike!
Hi, joe!
</pre></div>


<p><em>在定义可以接收一系列值的位置参数时，建议在函数内部为该变量命名时总是用<strong>复数</strong></em>，因为函数内部，总是需要 <code>for</code> 循环去迭代元组中的元素，这样的时候，名称的复数形式对代码的可读性很有帮助 —— 注意以上程序第二行。以中文为母语的人，在这个细节上常常感觉 “不堪重负” —— 因为中文的名词没有复数 —— 但必须习惯。（同样的道理，若是用拼音命名变量，就肯定是为将来挖坑……）</p>
<p><strong>注意</strong>：一个函数中，可以接收一系列值的位置参数只能有一个；并且若是还有其它位置参数存在，那就必须把这个可以接收一系列值的位置参数排在所有其它位置参数之后。</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">say_hi</span><span class="p">(</span><span class="n">greeting</span><span class="p">,</span> <span class="o">*</span><span class="n">names</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
        <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">&#39;{greeting}, {name.capitalize()}!&#39;</span><span class="p">)</span>

<span class="n">say_hi</span><span class="p">(</span><span class="s1">&#39;Hello&#39;</span><span class="p">,</span> <span class="s1">&#39;mike&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">,</span> <span class="s1">&#39;zeo&#39;</span><span class="p">)</span>
</pre></div>


<div class="highlight"><pre><span></span>Hello, Mike!
Hello, John!
Hello, Zeo!
</pre></div>


<h2>为函数的某些参数设定默认值</h2>
<p>可以在定义函数的时候，为某些参数设定默认值，这些有默认值的参数，又被称作关键字参数（Keyword Arguments）。从这个函数的 “用户” 角度来看，这些设定了默认值的参数，就成了 “可选参数”。</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">say_hi</span><span class="p">(</span><span class="n">greeting</span><span class="p">,</span> <span class="o">*</span><span class="n">names</span><span class="p">,</span> <span class="n">capitalized</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">capitalized</span><span class="p">:</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">capitalize</span><span class="p">()</span>
        <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">&#39;{greeting}, {name}!&#39;</span><span class="p">)</span>

<span class="n">say_hi</span><span class="p">(</span><span class="s1">&#39;Hello&#39;</span><span class="p">,</span> <span class="s1">&#39;mike&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">,</span> <span class="s1">&#39;zeo&#39;</span><span class="p">)</span>
<span class="n">say_hi</span><span class="p">(</span><span class="s1">&#39;Hello&#39;</span><span class="p">,</span> <span class="s1">&#39;mike&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">,</span> <span class="s1">&#39;zeo&#39;</span><span class="p">,</span> <span class="n">capitalized</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>


<div class="highlight"><pre><span></span>Hello, mike!
Hello, john!
Hello, zeo!
Hello, Mike!
Hello, John!
Hello, Zeo!
</pre></div>


<h2>可以接收一系列值的关键字参数</h2>
<p>之前我们看到，可以设定一个位置参数（Positional Argument），接收一系列的值，被称作 “Arbitrary Positional Argument”；</p>
<p>同样地，我们也可以设定一个可以接收很多值的关键字参数（Arbitrary Keyword Argument）。</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">say_hi</span><span class="p">(</span><span class="o">**</span><span class="n">names_greetings</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">greeting</span> <span class="ow">in</span> <span class="n">names_greetings</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
        <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">&#39;{greeting}, {name}!&#39;</span><span class="p">)</span>

<span class="n">say_hi</span><span class="p">(</span><span class="n">mike</span><span class="o">=</span><span class="s1">&#39;Hello&#39;</span><span class="p">,</span> <span class="n">ann</span><span class="o">=</span><span class="s1">&#39;Oh, my darling&#39;</span><span class="p">,</span> <span class="n">john</span><span class="o">=</span><span class="s1">&#39;Hi&#39;</span><span class="p">)</span>
</pre></div>


<div class="highlight"><pre><span></span>Hello, mike!
Oh, my darling, ann!
Hi, john!
</pre></div>


<p>既然在函数内部，我们在处理接收到的 Arbitrary Keyword Argument 时，用的是对字典的迭代方式，那么，在调用函数的时候，也可以直接使用字典的形式：</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">say_hi</span><span class="p">(</span><span class="o">**</span><span class="n">names_greetings</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">greeting</span> <span class="ow">in</span> <span class="n">names_greetings</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
        <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">&#39;{greeting}, {name}!&#39;</span><span class="p">)</span>

<span class="n">a_dictionary</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;mike&#39;</span><span class="p">:</span><span class="s1">&#39;Hello&#39;</span><span class="p">,</span> <span class="s1">&#39;ann&#39;</span><span class="p">:</span><span class="s1">&#39;Oh, my darling&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">:</span><span class="s1">&#39;Hi&#39;</span><span class="p">}</span>
<span class="n">say_hi</span><span class="p">(</span><span class="o">**</span><span class="n">a_dictionary</span><span class="p">)</span>

<span class="n">say_hi</span><span class="p">(</span><span class="o">**</span><span class="p">{</span><span class="s1">&#39;mike&#39;</span><span class="p">:</span><span class="s1">&#39;Hello&#39;</span><span class="p">,</span> <span class="s1">&#39;ann&#39;</span><span class="p">:</span><span class="s1">&#39;Oh, my darling&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">:</span><span class="s1">&#39;Hi&#39;</span><span class="p">})</span>
</pre></div>


<div class="highlight"><pre><span></span>Hello, mike!
Oh, my darling, ann!
Hi, john!
Hello, mike!
Oh, my darling, ann!
Hi, john!
</pre></div>


<p>至于在函数内部，你用什么样的迭代方式去处理这个字典，是你自己的选择：</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">say_hi_2</span><span class="p">(</span><span class="o">**</span><span class="n">names_greetings</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names_greetings</span><span class="p">:</span>
        <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">&#39;{names_greetings[name]}, {name}!&#39;</span><span class="p">)</span>
<span class="n">say_hi_2</span><span class="p">(</span><span class="n">mike</span><span class="o">=</span><span class="s1">&#39;Hello&#39;</span><span class="p">,</span> <span class="n">ann</span><span class="o">=</span><span class="s1">&#39;Oh, my darling&#39;</span><span class="p">,</span> <span class="n">john</span><span class="o">=</span><span class="s1">&#39;Hi&#39;</span><span class="p">)</span>
</pre></div>


<div class="highlight"><pre><span></span>Hello, mike!
Oh, my darling, ann!
Hi, john!
</pre></div>


<h2>函数定义时各种参数的排列顺序</h2>
<p>在定义函数的时候，各种不同类型的参数应该按什么顺序摆放呢？对于之前写过的 <code>say_hi()</code> 这个函数，</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">say_hi</span><span class="p">(</span><span class="n">greeting</span><span class="p">,</span> <span class="o">*</span><span class="n">names</span><span class="p">,</span> <span class="n">capitalized</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">capitalized</span><span class="p">:</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">capitalize</span><span class="p">()</span>
        <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">&#39;{greeting}, {name}!&#39;</span><span class="p">)</span>

<span class="n">say_hi</span><span class="p">(</span><span class="s1">&#39;Hi&#39;</span><span class="p">,</span> <span class="s1">&#39;mike&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">,</span> <span class="s1">&#39;zeo&#39;</span><span class="p">)</span>
<span class="n">say_hi</span><span class="p">(</span><span class="s1">&#39;Welcome&#39;</span><span class="p">,</span> <span class="s1">&#39;mike&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">,</span> <span class="s1">&#39;zeo&#39;</span><span class="p">,</span> <span class="n">capitalized</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>


<div class="highlight"><pre><span></span>Hi, mike!
Hi, john!
Hi, zeo!
Welcome, Mike!
Welcome, John!
Welcome, Zeo!
</pre></div>


<p>如果，你想给其中的 <code>greeting</code> 参数也设定个默认值怎么办？写成这样好像可以：</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">say_hi</span><span class="p">(</span><span class="n">greeting</span><span class="o">=</span><span class="s1">&#39;Hello&#39;</span><span class="p">,</span> <span class="o">*</span><span class="n">names</span><span class="p">,</span> <span class="n">capitalized</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">capitalized</span><span class="p">:</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">capitalize</span><span class="p">()</span>
        <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">&#39;{greeting}, {name}!&#39;</span><span class="p">)</span>

<span class="n">say_hi</span><span class="p">(</span><span class="s1">&#39;Hi&#39;</span><span class="p">,</span> <span class="s1">&#39;mike&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">,</span> <span class="s1">&#39;zeo&#39;</span><span class="p">)</span>
<span class="n">say_hi</span><span class="p">(</span><span class="s1">&#39;Welcome&#39;</span><span class="p">,</span> <span class="s1">&#39;mike&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">,</span> <span class="s1">&#39;zeo&#39;</span><span class="p">,</span> <span class="n">capitalized</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>


<div class="highlight"><pre><span></span>Hi, mike!
Hi, john!
Hi, zeo!

Welcome, Mike!
Welcome, John!
Welcome, Zeo!
</pre></div>


<p>但 <code>greeting</code> 这个参数虽然有默认值，可这个函数在被调用的时候，还是必须要给出这个参数，否则输出结果出乎你的想象：</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">say_hi</span><span class="p">(</span><span class="n">greeting</span><span class="o">=</span><span class="s1">&#39;Hello&#39;</span><span class="p">,</span> <span class="o">*</span><span class="n">names</span><span class="p">,</span> <span class="n">capitalized</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">capitalized</span><span class="p">:</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">capitalize</span><span class="p">()</span>
        <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">&#39;{greeting}, {name}!&#39;</span><span class="p">)</span>

<span class="n">say_hi</span><span class="p">(</span><span class="s1">&#39;mike&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">,</span> <span class="s1">&#39;zeo&#39;</span><span class="p">)</span>
</pre></div>


<div class="highlight"><pre><span></span>mike, john!
mike, zeo!
</pre></div>


<p>设定了默认值的 <code>greeting</code>，竟然不像你想象的那样是 “可选参数”！所以，你得这样写：</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">say_hi</span><span class="p">(</span><span class="o">*</span><span class="n">names</span><span class="p">,</span> <span class="n">greeting</span><span class="o">=</span><span class="s1">&#39;Hello&#39;</span><span class="p">,</span> <span class="n">capitalized</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">names</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">capitalized</span><span class="p">:</span>
            <span class="n">name</span> <span class="o">=</span> <span class="n">name</span><span class="o">.</span><span class="n">capitalize</span><span class="p">()</span>
        <span class="k">print</span><span class="p">(</span><span class="n">f</span><span class="s1">&#39;{greeting}, {name}!&#39;</span><span class="p">)</span>

<span class="n">say_hi</span><span class="p">(</span><span class="s1">&#39;mike&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">,</span> <span class="s1">&#39;zeo&#39;</span><span class="p">)</span>
<span class="n">say_hi</span><span class="p">(</span><span class="s1">&#39;mike&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">,</span> <span class="s1">&#39;zeo&#39;</span><span class="p">,</span> <span class="n">greeting</span><span class="o">=</span><span class="s1">&#39;Hi&#39;</span><span class="p">)</span>
</pre></div>


<div class="highlight"><pre><span></span>Hello, mike!
Hello, john!
Hello, zeo!
Hi, mike!
Hi, john!
Hi, zeo!
</pre></div>


<p>这是因为函数被调用时，面对许多参数，Python 需要按照既定的规则（即，顺序）判定每个参数究竟是哪一类型的参数：</p>
<blockquote>
<p><strong>Order of Arguments</strong>
1. Positional
1. Arbitrary Positional
1. Keyword
1. Arbitrary Keyword</p>
</blockquote>
<p>所以，即便你在定义里写成</p>
<div class="highlight"><pre><span></span><span class="k">def</span> <span class="nf">say_hi</span><span class="p">(</span><span class="n">greeting</span><span class="o">=</span><span class="s1">&#39;Hello&#39;</span><span class="p">,</span> <span class="o">*</span><span class="n">names</span><span class="p">,</span> <span class="n">capitalized</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
    <span class="o">...</span>
</pre></div>


<p>在调用该函数的时候，无论你写的是</p>
<div class="highlight"><pre><span></span><span class="n">say_hi</span><span class="p">(</span><span class="s1">&#39;Hi&#39;</span><span class="p">,</span> <span class="s1">&#39;mike&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">,</span> <span class="s1">&#39;zeo&#39;</span><span class="p">)</span>
</pre></div>


<p>还是</p>
<div class="highlight"><pre><span></span><span class="n">say_hi</span><span class="p">(</span><span class="s1">&#39;mike&#39;</span><span class="p">,</span> <span class="s1">&#39;john&#39;</span><span class="p">,</span> <span class="s1">&#39;zeo&#39;</span><span class="p">)</span>
</pre></div>


<p>Python 都会认为接收到的第一个值是 Positional Argument —— 因为在定义中，<code>greeting</code> 被放到了 Arbitrary Positional Arguments 之前。</p>
    </div><!-- /.entry-content -->

  </article>
</section>
        <section id="extras" class="body">
                <div class="blogroll">
                        <h2>blogroll</h2>
                        <ul>
                            <li><a href="http://getpelican.com/">Pelican</a></li>
                            <li><a href="http://python.org/">Python.org</a></li>
                            <li><a href="http://jinja.pocoo.org/">Jinja2</a></li>
                            <li><a href="#">You can modify those links in your config file</a></li>
                        </ul>
                </div><!-- /.blogroll -->
                <div class="social">
                        <h2>social</h2>
                        <ul>

                            <li><a href="#">You can add links in your config file</a></li>
                            <li><a href="#">Another social link</a></li>
                        </ul>
                </div><!-- /.social -->
        </section><!-- /#extras -->

        <footer id="contentinfo" class="body">
                <p>Powered by <a href="http://www.maxiaoan.com/">Maxiaoan</a></p>
        </footer><!-- /#contentinfo -->

</body>
</html>